<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>sweetalert的demo</title>
        <link rel="stylesheet" href="css/sweetalert.css" />
    </head>
    <body>
        <h1>sweetalert的demo</h1>
        <button id="getData" rel="content">获取数据</button>
        <div id="content">我是内容</div>
        <script src="http://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
        <script src="js/sweetalert.min.js"></script>
        <script>
             $(document).ready(function () {
                //删除
                $(document).on('click', '[id=getData]', function () {
                    var id = $(this).attr('rel');
                    swal({
                        title: "您确定要执行此操作吗？",
        //                text: "删除后将无法恢复，请谨慎操作！",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",
                        closeOnConfirm: false
                    }, function () {

                        $.ajax({
                            url: "../data/base.json",
                            data: {
                                app_api_id: id
                            },
                            type: 'get',
                            dataType:'json',
                            cache: false,
                            success: function (msg) {
                                if (msg.isOK) {
                                    swal("删除成功！", "", "success");
                                    $('.confirm').click(function () {   //额外绑定一个事件，当确定执行之后返回成功的页面的确定按钮，点击之后刷新当前页面或者跳转其他页面
                                        location.reload();
                                    });

                                } else {
                                    swal("删除失败！", "", "error");
                                }
                            }
                        });
                    });
                });




            });
        </script>
    </body>
</html>